import axios from "axios"
import { useState } from "react"
import { useEffect } from "react"

const UserIndex = () => {

  useEffect(() => {
    // 组件初始化时获取用户列表
    console.log("获取用户")
    axios.get("/api/users/listUser").then(res => {
      setUserList(res.data.data.userList)
    })
  }, [])


  const [userList, setUserList] = useState([])

  return (
    <div>
      用户列表

      <div>
        <ul>
          {
            userList.map((user, index) => {
              return (
                <li key={index}>{user.name} - {user.age}</li>
              )
            })
          }
        </ul>
      </div>
    </div>
  )
}

export default UserIndex